home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / gcc263-utildoc.lha / gnu / man / man1 / expr.1 < prev    next >
Encoding:
Text File  |  1994-12-19  |  5.2 KB  |  199 lines

  1.  
  2.  
  3.  
  4. EXPR(1L)                                                 EXPR(1L)
  5.  
  6.  
  7. NNAAMMEE
  8.        expr - evaluate expressions
  9.  
  10. SSYYNNOOPPSSIISS
  11.        eexxpprr expression...
  12.        eexxpprr {--help,--version}
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.        This  manual page documents the GNU version of eexxpprr.  eexxpprr
  16.        evaluates an expression and writes the result on its stan-
  17.        dard output.  Each token of the expression must be a sepa-
  18.        rate argument.  Operands are either  numbers  or  strings.
  19.        Strings  are  not  quoted for eexxpprr, though you may need to
  20.        quote them to protect them from the shell.   eexxpprr  coerces
  21.        anything appearing in an operand position to an integer or
  22.        a string depending on the operation being applied to it.
  23.  
  24.        The operators (in order of increasing precedence) are:
  25.  
  26.        _|      Yields its first argument if it is neither null nor
  27.               0,  otherwise  its  second  argument.   This is the
  28.               usual `or' operation.
  29.  
  30.        _&      Yields its first argument if  neither  argument  is
  31.               null or 0, otherwise 0.
  32.  
  33.        _<  _<_=  _=  _=_=  _!_=  _>_=  _>
  34.               Compare  their  arguments and return 1 if the rela-
  35.               tion is true, 0 otherwise.  (_=_= is  a  synonym  for
  36.               _=.)  eexxpprr tries to coerce both arguments to numbers
  37.               and do a numeric comparison; if it fails when  try-
  38.               ing  to coerce either argument it then does a lexi-
  39.               cographic comparison.
  40.  
  41.        _+  _-   Perform arithmetic operations.  Both arguments  are
  42.               coerced  to numbers; an error occurs if this cannot
  43.               be done.
  44.  
  45.        _*  _/  _%
  46.               Perform arithmetic operations (`%' is the remainder
  47.               operation, as in C).  Both arguments are coerced to
  48.               numbers; an error occurs if this cannot be done.
  49.  
  50.        _:      Perform  pattern  matching.   Its   arguments   are
  51.               coerced to strings and the second one is considered
  52.               to be a regular expression, with a  `^'  implicitly
  53.               added at the beginning.  The first argument is then
  54.               matched against this regular  expression.   If  the
  55.               match  succeeds  and part of the string is enclosed
  56.               in `\(' and `\)', that part is the value of  the  _:
  57.               expression; otherwise an integer whose value is the
  58.               number of characters matched is returned.   If  the
  59.               match fails, the _: operator returns the null string
  60.               if `\(' and `\)' are used, otherwise 0.   Only  one
  61.  
  62.  
  63.  
  64. FSF                    GNU Shell Utilities                      1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. EXPR(1L)                                                 EXPR(1L)
  71.  
  72.  
  73.               `\(' and `\)' pair can be used.
  74.  
  75.        In addition, the following keywords are recognized:
  76.  
  77.        mmaattcchh _s_t_r_i_n_g _r_e_g_e_x
  78.               An alternative way to do pattern matching.  This is
  79.               the same as ``_s_t_r_i_n_g :: _r_e_g_e_x''.
  80.  
  81.        ssuubbssttrr _s_t_r_i_n_g _p_o_s_i_t_i_o_n _l_e_n_g_t_h
  82.               Return the substring of _s_t_r_i_n_g beginning  at  _p_o_s_i_-
  83.               _t_i_o_n  with  length at most _l_e_n_g_t_h.  If either _p_o_s_i_-
  84.               _t_i_o_n or _l_e_n_g_t_h is negative or non-numeric, return a
  85.               null string.
  86.  
  87.        iinnddeexx _s_t_r_i_n_g _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s
  88.               Return the first position in _s_t_r_i_n_g where the first
  89.               character in  _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s  was  found.   If  no
  90.               character  in  _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s  is found in _s_t_r_i_n_g,
  91.               return 0.
  92.  
  93.        lleennggtthh _s_t_r_i_n_g
  94.               Return the length of _s_t_r_i_n_g.
  95.  
  96.        Parentheses are used for grouping  in  the  usual  manner.
  97.        The keywords cannot be used as strings.
  98.  
  99.    OOPPTTIIOONNSS
  100.        When  GNU  eexxpprr  is invoked with exactly one argument, the
  101.        following options are recognized:
  102.  
  103.        _-_-_h_e_l_p Print a usage message on standard output  and  exit
  104.               successfully.
  105.  
  106.        _-_-_v_e_r_s_i_o_n
  107.               Print  version  information on standard output then
  108.               exit successfully.
  109.  
  110. EEXXAAMMPPLLEESS
  111.        To add 1 to the shell variable _a:
  112.  
  113.               a=`expr $a + 1`
  114.  
  115.        The following may be used to print the non-directory  part
  116.        of the file name stored in variable _a (the value in _a need
  117.        not contain `/'):
  118.  
  119.               expr $a : '.*/\(.*\)' '|' $a
  120.  
  121.        Note the quoted shell metacharacters.
  122.  
  123.        eexxpprr returns the following exit status:
  124.  
  125.        0 if the expression is neither null nor 0,
  126.        1 if the expression is null or 0,
  127.  
  128.  
  129.  
  130. FSF                    GNU Shell Utilities                      2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. EXPR(1L)                                                 EXPR(1L)
  137.  
  138.  
  139.        2 for invalid expressions.
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. FSF                    GNU Shell Utilities                      3
  197.  
  198.  
  199.